<?php
class Validate_Password extends Zend_Validate_Abstract 
{
// Error label; @var const
const INVALID = 'passwordInvalid';
const INVALID_LENGTH = 'passwordBadLength';

// Error text; @var array
protected $_messageTemplates = array(
    self::INVALID => 'Value does not appear to be a valid password',
    self::INVALID_LENGTH => 'Value should have from 5 to 30 symbols'
);


// Password validation check for correct symbols lenght used; @param string $value is valided
public function isValid($value) 
{
    $this->_setValue($value);
    $validatorStringLength = new Zend_Validate_StringLength(4, 30);

    if (!preg_match("/^[~!@#\\$%\\^&\\*\\(\\)\\-_\\+=\\\\\/\\{\\}\\[\\].,\\?<>:;a-z0-9]*$/i", $value)) {
        $this->_error(self::INVALID);
        return false;
    } elseif (!$validatorStringLength->isValid($value)) {
        $this->_error(self::INVALID_LENGTH);
        return false;
    }

    return true;
}
}